import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/components/pages/Index'
import Notfound from '@/components/common/Notfound'

Vue.use(Router)

let router = new Router({
  routes: [
    {
      path: '/',
      component: Index,
      meta: {
        title: '首页'
      }
    },
    {
      path: '*',
      name: '404',
      component: Notfound
    }
  ]
})

router.beforeEach((to, from, next) => {
  /* let token = localStorage.getItem('access_token')
  let nowTime = new Date()
  if (to.matched.some(r => r.meta.requireAuth)) {
    if (token && (nowTime.getTime() < localStorage.getItem('expires_time') * 1000)) {
      next()
    } else {
      localStorage.clear()
      next({path: '/'})
    }
  } else {
    next()
  } */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
